Chart for WinRT > Chart Features > Markers and Labels > Mouse Interaction with ChartPanel |
The ChartPanel panel has support of mouse interaction. The ChartPanelAction enumeration specifies possible action for the chart panel objects. The ChartPanelAction enumeration includes the following members:
Member Name | Description |
None | No action |
MouseMove | Follow mouse |
LeftMouseButtonDrag | Can be dragged with left mouse button |
RightMouseButtonDrag | Can be dragged with right mouse button |
Using the Action property we can make a draggable element or element that follows the mouse pointer. For example, changing the Action property in the Crosshair sample we get a marker that can be moved by user:
XAML |
Copy Code
|
---|---|
<c1:ChartPanelObject x:Name="cross" Attach="None" Action="LeftMouseButtonDrag" DataPoint="0.5,0.5" HorizontalAlignment="Center" VerticalAlignment="Center"> </c1:ChartPanelObject> |
Using data binding it's easy to add label that shows the current coordinate:
XAML |
Copy Code
|
---|---|
<c1:ChartPanelObject x:Name="cross" Attach="None" Action="LeftMouseButtonDrag" DataPoint="0.5,0.5" HorizontalAlignment="Center" VerticalAlignment="Center"> <Grid DataContext="{Binding ElementName=cross}"> <Ellipse Fill="White" Stroke="Red" StrokeThickness="2" Width="30" Height="30" /> <TextBlock Text="{Binding DataPoint.Y}" FontWeight="Bold" VerticalAlignment="Center" HorizontalAlignment="Center"/> </Grid> </c1:ChartPanelObject> |
The property Attach allows you to stick the possible positions of the element to the nearest data point. It can be attached to a single coordinate(X or Y) or to both coordinates (XY).